<?php /* Smarty version 2.6.20, created on 2011-10-25 17:21:55
         compiled from _core/_include/module/_mvc/control/handlecontainercontract.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/_include/module/_mvc/control/handlecontainercontract.tpl', 21, false),)), $this); ?>
function HandleContainerContract(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  
  this._orderTrackId = (options && options.track) ? options.track : [];
  
  this._createElements();
};
HandleContainerContract.prototype._createElements = function() {
  var _self = this;
  
  for (var j = 0, jl = this._orderTrackId.length; j < jl; j++) {
  
    var order = DlmanageUtils.order(this._item.orders, this._orderTrackId[j]);
    var gui = this._gui.list[j];
    
    gui.orderType.appendChild(document.createTextNode(order.type));
    var span = document.createElement('span');
    span.style.margin = '0 0 0 20px';
    span.appendChild(document.createTextNode((order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_WEDDING)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') ? ' wedding date: ' : ' working date: '));
    gui.orderType.appendChild(span);
    gui.date.appendChild(document.createTextNode(SimpleDate.format(order.date)));
    gui.note.appendChild(MiscUtils.span(order.note));

    gui.pp.appendChild(document.createTextNode((order.photoname) ? order.photoname : '(None)'));
    gui.vp.appendChild(document.createTextNode((order.videoname) ? order.videoname : '(None)'));
    
    new TableContractProduct(gui.pProduct, MiscUtils.find(order.purchaseItems, [{ attrs: ['packageInc'], value: '', unequal: true}]), { parent: order, cancelOnly: true });
    new TableContractProduct(gui.additions, MiscUtils.find(order.purchaseItems, [{ attrs: ['packageInc'], value: ''}]), { parent: order, cancelOnly: true });
    var total = 0, stage = 0;
    for (var i = 0, il = order.payments.length; i < il; i++) {
      var p = order.payments[i];
      if (p.cancelled == 1) {
        continue;
      }
      total += parseFloat(p.amount, 10);
      stage = Math.max(stage, p.stage);
    }
    gui.price.appendChild(document.createTextNode((order.price > 0) ? '$' + (order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));

    var p = DlmanageUtils.total(order);
    if (order.price != p) {
      //gui.discount.appendChild(document.createTextNode( (((p - order.price) / p) * 100).toFixed(1) + '% Off' ));
    }
    
    
    var rules = DlmanageUtils.payment(order.type);
    
    if (rules[0]) {
      this._pay(gui.pay1, order, 1, rules[0]);
    } else {
      gui.pay1.container.style.display = 'none';
    }
    if (rules[1]) {
      this._pay(gui.pay2, order, 2, rules[1]);
    } else {
      gui.pay2.container.style.display = 'none';
    }
    if (rules[2]) {
      this._pay(gui.pay3, order, 3, rules[2]);
    } else {
      gui.pay3.container.style.display = 'none';
    }
    if (rules[3]) {
      this._pay(gui.pay4, order, 4, rules[3]);
    } else {
      gui.pay4.container.style.display = 'none';
    }
  }
  
  window.print();
};

HandleContainerContract.prototype._pay = function(gui, order, stage, rule) {
  gui.payment.appendChild(document.createTextNode((order.price > 0) ? '$' + (rule.perc * order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' + rule.title: ''));
  gui.payment.appendChild(document.createTextNode(' ' + rule.comment.toLowerCase()));
};